<?php

class Administracion extends Controller {

    public function  __construct()
    {
        parent::Controller();
        $this->load->database();
        $this->load->library('session');
    }

    
    public function index()
    {
        $this->load->view('administracion/index');
    }
    
    
    public function verFicha()
    {
        $this->load->view('administracion/ficha_generica');
    }
    
	public function verGastosCostos()
    {
        $this->load->view('administracion/verGastosCostos');
    }
    
    
	public function ingresarGastosCostos()
    {
        $this->load->view('administracion/ingresarGastosCostos');
    }
    
    
    public function editarCliente()
    {
        $this->load->view('cliente/editarCliente');
    }
    
    
    public function eliminarCliente()
    {
        $this->load->view('cliente/eliminarCliente');
    }
    
    
	public function gastosCostosSelect()
    {
        $start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
		$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 20;


        $this->db->select('gastos_costos.*');
        $this->db->from('gastos_costos');
        $this->db->order_by('gastos_costos.idGastosCostos');

        $this->db->limit($limit, $start);

        $query = $this->db->get();
        $results = $this->db->count_all('gastos_costos');
        $arr = array();
        foreach ($query->result() as $obj)
        {
            $arr[] = $obj;
        }
        echo '{success:true,results:'. $results .
                ',rows:'.json_encode($arr).'}';
    }

    
    public function clienteUpdate()
    {
            $data = array(
            	'idCliente' 			=> $field[0],
                'razon_social' 	=> $field[1],
                'nombre_fantasia'=> $field[2],
                'direccion' 	=> $field[3],
                'telefono' 		=> $field[4],
            	'email' 		=> $field[5],
            	'condpago' 		=> $field[6],
            		
            );
                $this->db->where('idCliente', $field[0]);
                $this->db->update('cliente', $data);
    }

    
    public function clienteDelete()
    {
        $records = explode(';', $_POST['postdata']);
        foreach($records as $id)
        {
            $this->db->where('idCliente', $id);
            $this->db->delete('cliente');
        }
    }
    
    
    public function gastosCostosInsert()
    {
    	if($_POST){
    		  
            $data = array(
            	'concepto'		=> $_POST['concepto'],
                'valor' 	 	=> $_POST['valor'],
                'fecha'			=> $_POST['fecha']
            );
            
        	$this->load->model('AdministracionModel');
            $this->AdministracionModel->insertarFormGastosCostos($data);
            echo "<script  language='javascript'>alert('Gasto ingresado exitosamente!');</script>";
            $this->ingresarGastosCostos();
            
    	}else{
    		echo "<script  language='javascript'>alert('Error: No existen datos para ingresar!');</script>";
    	    $this->ingresarGastosCostos();
    	}    	
    }
    
    
    
}
